package com.zhanghe.study.jdbc;

import java.sql.*;

public class MetaData {
    public static void main(String[] args) {
        Connection connection = DbUtils.getConnection();
        try {
            DatabaseMetaData metaData = connection.getMetaData();
            // 获取数据库产品的名称
            String name = metaData.getDatabaseProductName();
            // jdbc驱动的主版本号
            int majorVersion = metaData.getDriverMajorVersion();
            // jdbc驱动的次版本号
            int minorVersion =  metaData.getDriverMinorVersion();
            // 连接数据库的用户名
            String userName = metaData.getUserName();
            // 获取Mysql中有哪些数据库
            ResultSet resultSet = metaData.getCatalogs();
            // 数据库的版本号
            int databaseVersion = metaData.getDatabaseMajorVersion();
            System.out.println(name);
            System.out.println(majorVersion+"."+minorVersion);
            System.out.println(userName);
            System.out.println(databaseVersion);

            ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
            System.out.println(resultSetMetaData.getColumnName(0));

            while (resultSet.next()){
                System.out.print(resultSet.getString(1)+"\t");
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
                connection.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }

    }


}
